// ml:run = time -p $bin < input
#include <iostream>
#include <algorithm>

int const maxn = 50;
int a[maxn][maxn];
int b[maxn][maxn];

int n, m;

bool ordered(int a[])
{
    for (int i = 2; i <= m; i++)
        if (a[i] < a[i - 1]) return false;
    return true;
}

bool check_row(int a[])
{
    if (ordered(a)) return true;
    for (int i = 1; i <= m; i++) {
        for (int j = i + 1; j <= m; j++) {
            std::swap(a[i], a[j]);
            if (ordered(a)) return true;
            std::swap(a[i], a[j]);
        }
    }
    return false;
}

bool check_each()
{
    for (int i = 1; i <= n; i++) {
        if (!check_row(a[i])) return false;
    }
    return true;
}

void copy()
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            a[i][j] = b[i][j];
}

void swap_col(int y1, int y2)
{
    for (int i = 1; i <= n; i++)
        std::swap(a[i][y1], a[i][y2]);
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> m;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            std::cin >> a[i][j];
            b[i][j] = a[i][j];
        }

    if (check_each()) {
        std::cout << "YES\n";
        return 0;
    }
    for (int i = 1; i <= m; i++)
        for (int j = i + 1; j <= m; j++) {
            copy();
            swap_col(i, j);
            if (check_each()) {
                std::cout << "YES\n";
                return 0;
            }
        }
    std::cout << "NO\n";
}

